library TeamLocatorCommand initializer init requires LegacySystem

	private function TeamLocatorCommand takes nothing returns nothing
		local player p = GetTriggerPlayer()
        local integer i
        local integer i2
        local real currentlife
        local real liferatio
        local integer critical = 0
        local integer CorpsmanAlive = getInteger(null,"NumCorpsman")
        
        if GetConvertedPlayerId(p)<6 then
            set i = 1
        else
            set i = 6
        endif
        set i2=i+4
        if CorpsmanAlive>0 then
            loop
                exitwhen i>i2
                if i==10 then
                    set i=11
                endif
                set currentlife = GetWidgetLife(udg_Hero[i])
                if currentlife>0.405 then
                    set liferatio = currentlife/GetUnitState(udg_Hero[i],UNIT_STATE_MAX_LIFE)
                    if liferatio>0.75 then
                        call PingMinimapEx(GetUnitX(udg_Hero[i]), GetUnitY(udg_Hero[i]), 2.0, 0, 200, 0, false)
                    elseif liferatio>0.4 then
                        call PingMinimapEx(GetUnitX(udg_Hero[i]), GetUnitY(udg_Hero[i]), 3.0, 200, 200, 0, false)
                    else
                        set critical=1
                        call PingMinimapEx(GetUnitX(udg_Hero[i]), GetUnitY(udg_Hero[i]), 5.0, 200, 0, 0, false)
                    endif
                endif
                set i=i+1
            endloop
            if critical==1 then
                call StartSound(gg_snd_SentryOnline)
            endif
        else
            loop
                exitwhen i>i2
                if i==10 then
                    set i=11
                endif
                if GetWidgetLife(udg_Hero[i])>0.405 then
                    call PingMinimapEx(GetUnitX(udg_Hero[i]), GetUnitY(udg_Hero[i]), 2.0, 25, 25, 200, false)
                endif
                set i=i+1
            endloop
        endif
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		local integer i = 0
		set t = CreateTrigger()

		loop
			exitwhen i > 11
			call TriggerRegisterPlayerChatEvent(t, Player(i), "-tl", true)
			set i = i + 1
		endloop
		call TriggerAddAction(t,function TeamLocatorCommand)
	endfunction
endlibrary